package com.leyou.Item.service;

import com.leyou.Item.mapper.CategoryMapper;
import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.exception.LyException;
import com.leyou.item.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

//实现类
@Service
public class CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    public List<Category>  queryCategoryListByPid(Long pid) {
      Category t = new Category();
      //查询条件
      t.setParent_id(pid);
      List<Category> list = categoryMapper.select(t);//select(t)  t是一个对象 这个对象的非空属性就是查询条件
      //判断查询结果
      if(CollectionUtils.isEmpty(list)){
          //若查询为空返回404
          throw  new LyException(ExceptionEnum.CATEGORY_NOT_FOUND);
      }
      return  list;
    }
}
